package cn.bsb.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.bsb.pojo.Article;
import cn.bsb.pojo.DevUser;
import tk.mybatis.mapper.common.Mapper;

public interface ArticleMapper extends Mapper<Article> {
	
	//文章列表
	@Select("select * from article ORDER BY creattime DESC")
	public List<Article> getList();
	
	//查询后的文章列表
	@Select("select * from article where title LIKE CONCAT ('%',#{title},'%') ORDER BY creattime DESC")
	public List<Article> getSelectList(@Param("title") String title);
	
	//删除文章
	@Delete("delete from article where id=#{id}")
	public int deleteArticle(@Param("id")Long id);
	
	//文章的具体信息
	@Select("select * from article where id=#{id}")
	public Article getArticle(@Param("id") Long id);
	
	//根据用户id查询文章集合
	@Select("SELECT * FROM article WHERE dev_user_id=#{id} ORDER BY `creattime` DESC ")
	public List<Article> getArticles(@Param("id")Integer uid);
	//查询文章总数（用户）
	@Select("SELECT COUNT(*) FROM article WHERE dev_user_id =#{id}")
	public int getCount(@Param("id") Integer id);
	
	@Update("UPDATE article SET lik=lik+1 WHERE id=#{id}")
	public int like(@Param("id")Long id) ;
	@Update("UPDATE article SET thematic_id=1 WHERE thematic_id=#{thematic_id}")
	public int updateThematicid(@Param("thematic_id")Long thematic_id) ;
	
	//增加浏览量
	@Update("UPDATE article SET look=look+1 WHERE id=#{id}")
	public int addlook(@Param("id")int id);
	//按文章ID查作者
	public DevUser getDevUserByarticleId(@Param("id")Long id);
}
